package com.caiyi.financial.nirvana.sms.service;

import com.caiyi.financial.nirvana.sms.base.service.BaseService;
import com.caiyi.financial.nirvana.sms.entity.SmsLog;
import com.caiyi.financial.nirvana.sms.enums.SmsLogTypeEnum;
import com.caiyi.financial.nirvana.sms.mapper.SmsLogMapper;
import com.caiyi.financial.nirvana.sms.querybean.LogQueryBean;
import com.caiyi.financial.nirvana.sms.querybean.PageBean;
import com.caiyi.financial.nirvana.sms.vo.SmsLogVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SmsLogService extends BaseService<SmsLog> {
    @Autowired
    private SmsLogMapper smsLogMapper;

    public PageBean<SmsLogVo> getLogListByParams(LogQueryBean bean) {
        PageHelper.startPage(bean.getPageNum(), bean.getPageSize());
        List<SmsLogVo> list = smsLogMapper.selectLogList(bean);
        Page<SmsLogVo> page = (Page<SmsLogVo>) list;
        List<SmsLogVo> listSmsLogVo = new ArrayList<>();
        for (SmsLogVo log : list) {
            String typeName = null;
            Integer type = log.getType();
            for (SmsLogTypeEnum e : SmsLogTypeEnum.values()) {
                if (type.equals(e.index)) {
                    typeName = e.desc;
                }
            }
            log.setTypeName(typeName);
            listSmsLogVo.add(log);
        }
        PageBean<SmsLogVo> pageBean = new PageBean<>(listSmsLogVo);
        pageBean.setPages(page.getPages());
        pageBean.setTotal(page.getTotal());
        return pageBean;
    }
}
